package com.mvc.model;

import com.jfinal.plugin.activerecord.Model;
import com.jfinal.plugin.activerecord.Page;

/**
 * 祭拜记录
 */

public class Worship extends Model<Worship> {
	/**
	 * 
	 */
	private static final long serialVersionUID = 4180698238142535703L;

	/***
	 * 表字段
	 * 
	 */
	public static interface TableField {
		String ID = "id";
		String VENUEID = "venueId";
		String TRIBUTEID = "tributeId";
		String USERID = "userId";
		String CREATETIME = "createTime";
		String NAME ="name";
	}

	public static final Worship dao = new Worship();

	/***
	 * 关联用户表
	 * 
	 * @return
	 */
	public User getUser() {
		return User.dao.findById(getInt(TableField.USERID));
	}

	/***
	 * 关联贡品表
	 * 
	 * @return
	 */
	public Tribute getTribute() {
		return Tribute.dao.findById(getInt(TableField.TRIBUTEID));
	}

	/***
	 * 关联场馆表
	 * 
	 * @return
	 */
	public Venue getVenue() {
		return Venue.dao.findById(getInt(TableField.VENUEID));
	}

	/***
	 * 获取最新列表
	 * 
	 * @param req
	 * @return
	 */
	public Page<Worship> queryNewPage(int pageNumber, int pageSize) {

		String select = "select v.*";
		String formwhere = "from worship v where 1=1 order by v.createTime desc ";
		return dao.paginate(pageNumber, pageSize, select, formwhere);
	}

	/***
	 * 根据场馆祭拜记录获取祭品列表
	 * 
	 * @param req
	 * @return
	 */
	public Page<Worship> queryVenuePage(int pageNumber, int pageSize,
			int venueId) {

		String select = "select v.*";
		String formwhere = "from worship v where v.type=1 and v.venueId=? order by v.createTime desc ";
		return dao.paginate(pageNumber, pageSize, select, formwhere, venueId);
	}

}
